"""
@name : 04.集合
@author : wenyao
@projectname: 空气质量.py
"""
#  什么是集合( set )
# • 集合是一个无序的，不重复的数据组合
# • 集合是一个只含有key的字典
#  集合的作用
# • 去重：把一个列表变成集合，就自动去重了
# • 关系测试：测试两组数据之前的交集、差集、并集等关系

#天生去重
# >>> a = {1,2,3}
# >>> a = {1,[1],3}
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: unhashable type: 'list'
# >>> a = {1,2,2,3}
# >>> a
# {1, 2, 3}
# >>> type(a)
# <class 'set'>
# >>> set("aaabbccc")
# {'a', 'b', 'c'}

#有一个随机字符串“skefiawefaksdjfawe230934认可度nvfgaiufe”，统计每个字符出现的次数
# str1 = "sdksakdjfweisfksdj"
# s1 = set(str1)
# for i in s1:
#     print(f'{i}出现了{str1.count(i)}次')

##集合的添加和删除
# >>> a
# {1, 2, 3}
# >>> a.add(4)
# >>> a
# {1, 2, 3, 4}
# >>> a.update("xyz")
# >>> a
# {'x', 1, 2, 3, 4, 'y', 'z'}
# >>> s
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 's' is not defined
# >>> a
# {'x', 1, 2, 3, 4, 'y', 'z'}
# >>> a.remove("x")
# >>> a.remove("5")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# KeyError: '5'
# >>> a.discard('5')
# >>> a.discard('y')
# >>> a
# {1, 2, 3, 4, 'z'}


#集合的运算  交集 并集 差集 对称差集
# >>> s1 = {1,2,3}
# >>> s2 = {2,3,4}
# >>> s1 | s2
# {1, 2, 3, 4}
# >>> s1 & s2
# {2, 3}
# >>> s1 - s2
# {1}
# >>> s2 - s1
# {4}
# >>> s1 ^ s2
# {1, 4}

#互送礼物
#a = ["a","b","c","d","e"]
